package com.itheima.web.controller;

import com.itheima.domain.mongo.Freeze;
import com.itheima.domain.mongo.UnFreeze;
import com.itheima.web.manager.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    private UserManager userManager;

    // 用户列表
    @GetMapping("/manage/users")
    public ResponseEntity findUserInfoByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return userManager.findUserInfoByPage(pageNum, pageSize);
    }

    // 用户详情
    @GetMapping("/manage/users/{userId}")
    public ResponseEntity findUserInfoById(@PathVariable Long userId) {
        return userManager.findUserInfoById(userId);
    }

    // 动态列表
    @GetMapping("/manage/messages")
    public ResponseEntity messages(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "uid", required = false) Long userId,
            Integer state) {
        return userManager.messages(userId, state, pageNum, pageSize);
    }

    // 单条动态
    @GetMapping("/manage/messages/{publishId}")
    public ResponseEntity findMovementVoById(@PathVariable String publishId){
        // 调用manager
        return userManager.findMovementVoById(publishId);
    }

    // 动态评论列表
    @GetMapping("/manage/messages/comments")
    public ResponseEntity findCommentVoByPage(
            @RequestParam(value = "page",defaultValue = "1")Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10") Integer pageSize,
            @RequestParam(value = "messageID") String publishId){
        // 调用manager
        return userManager.findCommentVoByPage(publishId,pageNum,pageSize);
    }

    //用户冻结操作
    @PostMapping("/manage/users/freeze")
    public ResponseEntity freeze(@RequestBody Freeze freeze){

        return userManager.freeze(freeze);
    }

    //用户解冻
    @PostMapping("/manage/users/unfreeze")
    public ResponseEntity unfreeze(@RequestBody UnFreeze unFreeze) {

        return userManager.unfreeze(unFreeze);
    }

    //动态审核通过
//    @PostMapping("/manage/messages/pass")
//    public void messagesReview(List<String> param){
//        userManager.messagesReview(param);
//    }
    @PostMapping("/manage/messages/pass")
    public void messagesReview(@RequestBody List<String> param){
        userManager.messagesReview(param);
    }

    //动态拒绝
    @PostMapping("/manage/messages/reject")
    public void  messagesReviewFalse(@RequestBody List<String> param){
        userManager.messagesReviewFalse(param);
    }







}
